package org.zdc.utils;
import nme.display.DisplayObject;
import nme.display.DisplayObjectContainer;

class UIHelper 
{
	
	/**
	 * 把显示对象置顶
	 * @param	dio
	 */
	public static inline function top(dio:DisplayObject):Void {
		var p:DisplayObjectContainer = dio.parent;
		if (p != null) {
			p.setChildIndex(dio, p.numChildren - 1);
		}
	}
	
	/**
	 * 把数组元素全部置顶（左边最前）
	 * @param	dios
	 */
	public static inline function topAll(dios:Array<DisplayObject>):Void {
		for (i in dios.length...0) {
			top(dios[i]); 
		}
	}
	
	/**
	 * 把对象置底
	 * @param	dio
	 */
	public static inline function bottom(dio:DisplayObject):Void {
		var p:DisplayObjectContainer = dio.parent;
		if (p != null) {
			p.setChildIndex(dio, 0);
		}
	}
	
	/**
	 * 把数组元素全部置底（左边最底）
	 * @param	dios
	 */
	public static inline function bottomAll(dios:Array<DisplayObject>):Void {
		for (i in dios.length...0) {
			bottom(dios[i]); 
		}
	}
	
	/**
	 * 首字母大写
	 * @param	str
	 * @return
	 */
	public static inline function capitalize(str:String):String {
		return str.substr(0, 1).toUpperCase() + str.substr(1);
	}
	
	/**
	 * 首字母小写
	 * @param	str
	 * @return
	 */
	public static inline function uncapitalize(str:String):String {
		return str.substr(0, 1).toLowerCase() + str.substr(1);
	}
}